import random
import time
from tkinter import *


root = Tk()
root.title('2201点名系统')
root.iconbitmap(bitmap="favicon.ico")
title=Label(root,text=' 欢迎使用2201班随机点名系统！',font=("宋体",25))
title.pack()
root.config()
mingdan=['卫新宇','王尚熙','宁  钰','黄天龙','张奥玮','刘思如','王京晶','林怡彤','时培杰','杨柳炜','袁紫涵','张卓琳','孙艺丹','郭泽坤','樊思晨','马梓航','崔梦垚','林钲皓','高梓萌','李嘉图','靳昊润','张巧巧','董晓泰','商妍茹','毕昭阳','胡川琪','吕承玺','张颢译','景元瑞','柴嘉晨','梁靖怡','许薰元','郭亚鑫','程相杰','尤常凯','王浩宇','马佳敏','李金阳','宋文晖','李季泽','弓士森','杨子轩','上官佐','胡梦涛','宁一张','宁一弛','张宸坤']
names=mingdan
name=StringVar()
name.set('      ')
box=StringVar()
box.set((' '))
global key
hai=0
key=0
value=0
t=0
def getname():
        global key
        global name
        global names
        key=0
        while key==0:
                time.sleep(0.075)
                name.set(random.choice(names))
                
                root.update()
def nameselect():
        global value
        global key
        global names
        global name
        global selectlist
        global t
        global suiji
        name.set((random.choice(names)))
        if name.get()!='' and key==0:
                if names!=[] and names!=['      ']:
                        selectlist.config(state=NORMAL)
                        if t!=0:
                                selectlist.insert(END,'，')
                        selectlist.insert(END, name.get())
                        names.remove(name.get())
                        t+=1
                        selectlist.config(state=DISABLED)
                if names==[]:
                        names=['      ']
                        key=1
                
def namestop():
        global key
        key=1
def namedel():
        global selectlist
        global t
        global names
        global mingdan
        global suiji
        global key
        names=['卫新宇','王尚熙','宁  钰','黄天龙','张奥玮','刘思如','王京晶','林怡彤','时培杰','杨柳炜','袁紫涵','张卓琳','孙艺丹','郭泽坤','樊思晨','马梓航','崔梦垚','林钲皓','高梓萌','李嘉图','靳昊润','张巧巧','董晓泰','商妍茹','毕昭阳','胡川琪','吕承玺','张颢译','景元瑞','柴嘉晨','梁靖怡','许薰元','郭亚鑫','程相杰','尤常凯','王浩宇','马佳敏','李金阳','宋文晖','李季泽','弓士森','杨子轩','上官佐','胡梦涛','宁一张','宁一弛','张宸坤']
        selectlist.config(state=NORMAL)
        t=0
        key=0
        selectlist.delete(0.1,END)
        selectlist.config(state=DISABLED)
        suiji.destory()
        name.set((random.choice(names)))
        suiji=Label(mingzi,textvariable=name,font=("宋体",30,'bold'),relief=FLAT)
        suiji.pack(side=LEFT,padx=200,pady=20)
def gettime():
      timestr = time.strftime("%H:%M:%S")
      lb.configure(text=timestr)
      root.after(1000,gettime)

mingzi=Frame(root)
suiji=Label(mingzi,textvariable=name,font=("宋体",30,'bold'),relief=FLAT)
suiji.pack(side=LEFT,padx=200,pady=20)

selectlist=Text(mingzi,font=("宋体",20,'bold'),relief=FLAT,width=24, height=5,state=DISABLED)
scrollbar = Scrollbar(mingzi,command=selectlist.yview)
scrollbar.pack(side=RIGHT, fill=Y)
selectlist.pack(side=RIGHT)
selectlist.config(yscrollcommand=scrollbar.set)
mingzi.pack(pady=20)

anniu=Frame(root)
start=Button(anniu,text='开始',command=getname,relief=GROOVE)
start.pack(side=LEFT,anchor=SW,ipadx=50,ipady=10,padx=50,pady=50)
select=Button(anniu,text='点名',command=nameselect,relief=GROOVE)
select.pack(side=LEFT,anchor=SW,ipadx=50,ipady=10,padx=50,pady=50)
dele=Button(anniu,text='清除',command=namedel,relief=GROOVE)
dele.pack(side=LEFT,anchor=SW,ipadx=50,ipady=10,padx=50,pady=50)
stop=Button(anniu,text='停止',command=namestop,relief=GROOVE)
stop.pack(side=LEFT,anchor=SW,ipadx=50,ipady=10,padx=50,pady=50)
anniu.pack()

lb = Label(root,text='',font=("宋体",15))
lb.pack(side=LEFT)
gettime()
shuiyin=Label(root,text='——Made by lv',font=("宋体",15))
shuiyin.pack(side=RIGHT)
root.mainloop()
